package com.tjetc;


import com.tjetc.domain.Adopter;
import com.tjetc.proxy.ClientProxy;
import com.tjetc.service.AdminService;
import com.tjetc.service.AdoptService;
import com.tjetc.view.AdminView;
import com.tjetc.view.AdoptApplicationView;
import com.tjetc.vo.AppData;
import com.tjetc.vo.Result;

import java.util.Scanner;

public class ClientMain {
    private static Scanner sc = new Scanner(System.in);
    private static AdminService adminService = ClientProxy.getProxyInstance(AdminService.class);
    private static AdoptService adoptService=ClientProxy.getProxyInstance(AdoptService.class);

    public static void main(String[] args) {
        while (true) {
            System.out.println("1.管理员登录");
            System.out.println("2.领养人登录");
            System.out.println("3.领养人注册");
            System.out.println("0.退出系统");
            System.out.println("请输入你的选择0~3");
            int i = sc.nextInt();
            switch (i) {
                case 1:
                    adminLogin();
                    AdminView adminView =new AdminView();
                    adminView.start();
                    break;
                case 2:
                    adoptLogin();
                    AdoptApplicationView adoptApplicationView=new AdoptApplicationView();
                    adoptApplicationView.start();
                    break;
                case 3:
                    adoptRegister();
                    break;
                case 0:
                    System.exit(0);
                default:
                    System.out.println("请重新输入");
            }
        }
    }

    private static void adoptRegister() {
        System.out.println("请输入用户名");
        String username = sc.next();
        System.out.println("请输入密码");
        String password=sc.next();
        System.out.println("请输入姓名");
        String name = sc.next();
        System.out.println("请输入邮箱");
        String email = sc.next();
        System.out.println("请输入手机号");
        String phone = sc.next();
        System.out.println("请输入地址");
        String address = sc.next();
        //创建对象
        Adopter adopter=new Adopter().setUsername(username).setPassword(password).setName(name)
                .setEmail(email).setPhone(phone).setAddress(address);
        Result result=adoptService.register(adopter);
        System.out.println(result.getMsg());
    }

    private static void adoptLogin() {
        System.out.println("请输入用户名");
        String username = sc.next();
        System.out.println("请输入密码");
        String password = sc.next();
        Result result = adoptService.login(username, password);
        if (result.getCode() == 200) {
            AppData.adopter = (Adopter) result.getData();
        }
        System.out.println(result.getMsg());
    }

    private static void adminLogin() {
        System.out.println("请输入用户名");
        String username = sc.next();
        System.out.println("请输入密码");
        String password = sc.next();
        Result result = adminService.login(username, password);
        System.out.println(result.getMsg());
    }

}
